<template>
	<view class="box">
		<view class="xiaohei fonweight" style="font-size:48rpx;">Hi，你的生日是哪天呢?</view>
		<view class="xiaohui strongtext margin_top">正确的生日才能匹配，你也会收到来自朋友的祝福</view>
		<picker-view v-if="visible" :indicator-style="indicatorStyle" :value="value" @change="bindChange"
			class="picker-view">
			<picker-view-column>
				<view class="item" v-for="(item,index) in years" :key="index">{{item}}年</view>
			</picker-view-column>
			<picker-view-column>
				<view class="item" v-for="(item,index) in months" :key="index">{{item}}月</view>
			</picker-view-column>
			<picker-view-column>
				<view class="item" v-for="(item,index) in days" :key="index">{{item}}日</view>
			</picker-view-column>
		</picker-view>
		<view class="flexcenter">
			<view class="margin_top6 denglhbtn flexcenter touming" @click="tzdahb">下一步</view>
		</view>
		<!-- 跳转到爱好标签{{year}}年{{month}}月{{day}}日 -->
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			const date = new Date()
			const years = []
			const year = date.getFullYear()
			const months = []
			const month = date.getMonth() + 1
			const day = date.getDate()
			for (let i = 1950; i <= date.getFullYear(); i++) {
				years.push(i)
			}
			for (let i = 1; i <= 12; i++) {
				months.push(i)
			}
			return {
				title: 'picker-view',
				years,
				year,
				months,
				month,
				days: [],
				day,
				value: [9999, month - 1, day - 1],
				visible: true,
				indicatorStyle: `height: 50px;`

			}
		},
		methods: {
			// 获取该年该月的天数
			getDaysInYearMonth(year, month) {
				// 每一次进行更新前,先清空日期数组
				this.days = [],
					month = parseInt(month, 10);
				// javascript中Date()对象的getDate()是获取时间对象对应于一个月中的某一天（1~31），当设置为0的时候，getDate()返回的就是最后一天，刚好对应我们需要的值。
				var date = new Date(year, month, 0);
				console.log(date.getDate())
				for (var i = 1; i <= date.getDate(); i++) {
					console.log(i)
					this.days.push(i)
				}
			},
			bindChange: function(e) {
				const val = e.detail.value
				this.year = this.years[val[0]]
				this.month = this.months[val[1]]
				this.getDaysInYearMonth(this.year, this.month)
				this.day = this.days[val[2]]
			},
			// 跳转到爱好标签
			tzdahb() {
				uni.showLoading({
					mask:true,
					title:"请稍后"
				})
				httpRequest.request('/api/user/profile', 'GET', {
					birthday:this.year + "-" + this.month + "-" + this.day
				}).then(res => {
					uni.hideLoading()
					if(res.code==1){
						uni.navigateTo({
							url: '/pages/login/xuanzeahbq'
						})
					}else{
						httpRequest.toast(res.msg)
					}
				})
			},
		}
	}
</script>

<style>
	.denglhbtn {
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 800;
		color: #FFFFFF;
		width: 590rpx;
		height: 80rpx;
		background: #2361FF;
		border-radius: 52rpx;
	}

	.picker-view {
		width: 750rpx;
		height: 600rpx;
		margin-top: 20rpx;
	}

	.item {
		line-height: 100rpx;
		text-align: center;
	}

	.tupian {
		width: 250rpx;
		height: 250rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.box {
		padding: 229rpx 48rpx 30rpx;
	}
</style>